package com.sgzn.sgpay.service.impl;

import com.sgzn.sgpay.enums.SgsResponseCode;
import com.sgzn.sgpay.model.request.SgsShopIncomePreInfoRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.result.SgsShopIncomePreInfoResult;
import com.sgzn.sgpay.model.response.vo.ShopVo;
import com.sgzn.sgpay.persistence.domain.TShop;
import com.sgzn.sgpay.persistence.manager.ShopDaoManager;
import com.sgzn.sgpay.service.SgsShopIncomePreInfoService;
import com.sgzn.sgpay.service.support.SgsResponseUtil;
import com.sgzn.sgpay.util.ArgsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 门店收益前查询展示信息服务实现类
 * @author huangsenguang
 * @version Id: SgsShopIncomePreInfoServiceImpl.java, v 0.1 2018/5/30 13:52 huangsenguang Exp $$
 */
@Slf4j
@Service
public class SgsShopIncomePreInfoServiceImpl implements SgsShopIncomePreInfoService {
    @Resource
    private ShopDaoManager shopDaoManager;

    @Override
    public SgsResultResponse<SgsShopIncomePreInfoResult> queryInfo(SgsShopIncomePreInfoRequest request) {
        //根据商户ID查询所有门店
        List<TShop> shoplist = shopDaoManager.getByMch(request.getMchId());
        ArgsUtils.notEmpty(shoplist, SgsResponseCode.C_SHOP_NOT_FOUND.getResponseCode(), SgsResponseCode.C_SHOP_NOT_FOUND.getResponseDesc());
        SgsShopIncomePreInfoResult result = getSgsShopIncomePreInfoResult(this.getShopVoList(shoplist));
        return SgsResponseUtil.INSTANCE.success(result);
    }

    private SgsShopIncomePreInfoResult getSgsShopIncomePreInfoResult(List<ShopVo> shopVoList) {
        SgsShopIncomePreInfoResult result = new SgsShopIncomePreInfoResult();
        result.setShopVoList(shopVoList);
        return result;
    }

    /**
     * 获取下拉门店列表
     * @param shopList
     * @return
     */
    private List<ShopVo> getShopVoList(List<TShop> shopList) {
        List<ShopVo> voList = new ArrayList<>();
        for (TShop tShop : shopList) {
            ShopVo shopVo = new ShopVo();
            shopVo.setShopId(tShop.getShopId());
            shopVo.setShopName(tShop.getShopName());
            voList.add(shopVo);
        }
        log.info("List<ShopVo>:{}", voList.toString());
        return voList;
    }
}

